package com.kingdee.eas.xbwebservice.webservice;

import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.message.SOAPHeaderElement;

import com.kingdee.bos.BOSObjectFactory;
import com.kingdee.bos.orm.core.ORMEngine;
import com.kingdee.bos.webservice.BeanConvertHelper;
import com.kingdee.bos.webservice.WSConfig;
import com.kingdee.bos.webservice.WSInvokeException;

public class WSXBWebServiceFacadeSrvProxy {

	public String invoke(String methodName, String arg) throws WSInvokeException {
		try {
			return getController().invoke(methodName, arg);
		} catch (Throwable e) {
			throw new WSInvokeException(e);
		}
	}

	public byte[] getBytes(String methodName, String args) throws WSInvokeException {
		try {
			return getController().getBytes(methodName, args);
		} catch (Throwable e) {
			throw new WSInvokeException(e);
		}
	}

	public String testWebService(String arg1) throws WSInvokeException {
		try {
			return getController().testWebService(arg1);
		} catch (Throwable e) {
			throw new WSInvokeException(e);
		}
	}

	private com.kingdee.eas.xbwebservice.IXBWebServiceFacade getController() {
		try {
			if (WSConfig.getRomoteLocate() != null && WSConfig.getRomoteLocate().equals("false")) {
				Message message = MessageContext.getCurrentContext().getRequestMessage();
				SOAPEnvelope soap = message.getSOAPEnvelope();
				SOAPHeaderElement headerElement = soap.getHeaderByName(WSConfig.loginQName, WSConfig.loginSessionId);
				String SessionId = headerElement.getValue();
				return (com.kingdee.eas.xbwebservice.IXBWebServiceFacade) BOSObjectFactory.createBOSObject(SessionId,
						"com.kingdee.eas.xbwebservice.XBWebServiceFacade");
			} else {
				return (com.kingdee.eas.xbwebservice.IXBWebServiceFacade) BOSObjectFactory.createRemoteBOSObject(WSConfig.getSrvURL(),
						"com.kingdee.eas.xbwebservice.XBWebServiceFacade", com.kingdee.eas.xbwebservice.IXBWebServiceFacade.class);
			}
		} catch (Throwable e) {
			return (com.kingdee.eas.xbwebservice.IXBWebServiceFacade) ORMEngine.createRemoteObject(WSConfig.getSrvURL(),
					"com.kingdee.eas.xbwebservice.XBWebServiceFacade", com.kingdee.eas.xbwebservice.IXBWebServiceFacade.class);
		}
	}

	private BeanConvertHelper getBeanConvertor() {
		return new BeanConvertHelper();
	}

}